// student.ts - 添加学生活动相关接口
import {request, post, get} from '@/utils/request.ts';

// 学生工作台API
export const getStudentDashboard = (userId: number) => {
    return get(`/api/student/dashboard?userId=${userId}`);
};

// 学生侧边栏API
export const getStudentSidebar = (userId: number) => {
    return get(`/api/student/sidebar?userId=${userId}`);
};

// ==================== 学生活动相关接口 ====================

// 学生每日活动状态统计
export const getStudentDailyStatus = (userId: number, date: string) => {
    return get(`/api/user-activities/daily-status?userId=${userId}&date=${date}`);
};

// 学生指定日期活动列表
export const getStudentActivitiesByDate = (userId: number, date: string) => {
    return get(`/api/user-activities/by-date?userId=${userId}&date=${date}`);
};

// 学生打卡
export const studentCheckin = (activityId: any, params: any) => {
    return request({
        url: `/api/user-activities/checkin?activityId=${activityId}`,
        method: 'POST',
        data: params,
    });
};
//  所有活动
export const getAllActivities = (userId: number, keyword?: string, baseId?: string, fee?: string) => {
    const params: any = { userId };
    if (keyword) params.keyword = keyword;
    if (baseId) params.baseId = baseId;
    if (fee) params.fee = fee;
    return get('/api/user-activities/list', params);
};
//  我参与的活动
export const getJoinedActivities = (userId: number, keyword?: string, baseId?: string, fee?: string) => {
    const params: any = { userId };
    if (keyword) params.keyword = keyword;
    if (baseId) params.baseId = baseId;
    if (fee) params.fee = fee;
    return get('/api/user-activities/joined', params);
};

// 学生报名活动
export const studentSignupActivity = (userId: number, activityId: number) => {
    return post(`/api/user-activities/signup?userId=${userId}&activityId=${activityId}`);
};

// 学生取消报名
export const studentCancelSignup = (userId: number, activityId: number) => {
    return post('/api/user-activities/cancel-signup', { userId, activityId });
};

// 活动分类
export const getActivityCategories = () => {
    return get('/api/activities/categories');
};

// 活动基地
export const getActivityBases = () => {
    return get('/api/activity-bases');
};

// 其他现有接口保持不变...
export const fetchStudentScheduleByDateRange = (
    classId: number,
    startDate: string,
    endDate: string
) => {
    const params = new URLSearchParams();
    params.append('classId', classId.toString());
    params.append('startDate', startDate);
    params.append('endDate', endDate);
    return get(`/api/schedules/student?${params.toString()}`);
};

export const fetchCourseCategories = () => {
    return get('/api/courses/categories');
};

export const fetchTermWeeks = (termId: number, startDay = 1) => {
    return get(`/api/weeks/by-term?termId=${termId}&startDay=${startDay}`);
};


export const fetchAllTerms = () => {
    return get('/api/terms');
};
// ==================== 通知相关接口 ====================

/**
 * 获取通知列表
 * @param userId 用户ID
 * @param tabType 标签类型："received"(收到的) 或 "published"(发布的)
 * @param typeId 通知类型ID（可选）
 * @param page 页码（可选，默认1）
 * @param size 每页大小（可选，默认10）
 */
export const fetchNotices = (
    userId: number,
    tabType: 'received' | 'published',
    typeId?: number,
    page?: number,
    size?: number
) => {
    const params: any = {
        userId,
        tabType
    };

    if (typeId) params.typeId = typeId;
    if (page) params.page = page;
    if (size) params.size = size;

    return get('/api/notices', params);
};

/**
 * 获取所有通知类型
 */
export const fetchNoticeTypes = () => {
    return get('/api/notices/types');
};

/**
 * 标记通知为已读
 * @param noticeId 通知ID
 * @param userId 用户ID
 */
export const markNoticeAsRead = (noticeId: number, userId: number) => {
    return post(`/api/notices/${noticeId}/read?userId=${userId}`);
};


/**
 * 获取通知详情
 * @param noticeId 通知ID
 * @param tabType 标签类型（用于确定显示哪些额外信息）
 */
export const fetchNoticeDetail = (noticeId: number) => {
    return get(`/api/notices/${noticeId}`);
};


/**
 * 根据活动ID获取活动详情
 * @param activityId 活动ID
 * @param userId 用户ID（可选，用于检查是否已报名）
 */
export const getActivityDetail = (activityId: number, userId?: number) => {
    const params: any = { activityId };
    if (userId) params.userId = userId;
    return get(`/api/user-activities/details`, params);
};
